// CommandLine.h
// (c) 2011, Charles Lechasseur
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#pragma once


namespace RG64
{

    //
    // Simple class to parse the Regsvr64 command line. Not generic at all.
    //
    class CommandLine
    {
    public:
        //
        // Possible values determining whether DllRegisterServer/UnregisterServer is called.
        //
        enum RegServerFlag {
            RegServer,
            UnRegServer,
            NoRegServer
        };

        //
        // Possible values determining whether DllInstall/Uninstall is called.
        //
        enum InstallFlag {
            Install,
            Uninstall,
            NoInstall
        };

                        CommandLine(const char* const p_pCmdLine);

                        //
                        // Returns the original command-line, as passed to the program.
                        //
                        // @return Complete command-line.
                        //
        const std::string&
                        OriginalCommandLine() const
                        {
                            return m_CmdLine;
                        }

                        //
                        // Returns the name of the DLL to act upon.
                        //
                        // @return Name of DLL.
                        //
        const std::string&
                        DllName() const
                        {
                            return m_DllName;
                        }

                        //
                        // Returns a flag indicating whether DllRegisterServer/UnregisterServer should be called.
                        //
                        // @return Flag value.
                        //
        RegServerFlag   GetRegServerFlag() const
                        {
                            return m_RegServerFlag;
                        }

                        //
                        // Returns a flag indicating whether DllInstall/Uninstall should be called.
                        //
                        // @return Flag value.
                        //
        InstallFlag     GetInstallFlag() const
                        {
                            return m_InstallFlag;
                        }

                        //
                        // Returns the optional command-line to pass to DllInstall.
                        //
                        // @return DllInstall command-line. Can be empty.
                        //
        const std::wstring&
                        InstallCmdLine() const
                        {
                            return m_InstallCmdLine;
                        }

                        //
                        // Returns whether to install in silent mode or not.
                        //
                        // @return true for silent mode.
                        //
        bool            IsSilent() const
                        {
                            return m_Silent;
                        }

                        //
                        // Returns whether the command-line is considered "complete".
                        // If not, no action should be taken and help should be shown.
                        //
                        // @return true if command-line is complete.
                        //
        bool            Complete() const
                        {
                            return m_Complete;
                        }

    private:
        std::string     m_CmdLine;              // The complete command-line.
        std::string     m_DllName;              // Name of DLL to act upon.
        RegServerFlag   m_RegServerFlag;        // Flag indicating how to call DllRegisterServer/UnregisterServer.
        InstallFlag     m_InstallFlag;          // Flag indicating how to call DllInstall/Uninstall.
        bool            m_UnregFlag;            // Internal flag to remember if the unregister command-line option has been seen.
        std::wstring    m_InstallCmdLine;       // Optional command line for DllInstall.
        bool            m_Silent;               // Whether to run in silent mode (no dialog boxes).
        bool            m_Complete;             // Whether command-line is complete or not.

        void            SetInstallCmdLine(const std::string& p_CmdLine);

        // THESE METHODS ARE NOT IMPLEMENTED
                        CommandLine(const CommandLine&);
        CommandLine&    operator=(const CommandLine&);
    };

} // namespace RG64
